package com.vsoft.sms_cm;
import redis.clients.jedis.Jedis;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.vsoft.framework.core.BaseException;
import com.vsoft.framework.core.BusiObj;
import com.vsoft.framework.core.db.DBTrans;
import com.vsoft.framework.core.db.OperAgent;
import com.vsoft.framework.core.db.SQLArgs;
class MultiThreadRedis extends Thread
{
	private static Logger vLogger = Logger.getLogger(MultiThreadRedis.class);
	private static String vName = MultiThreadRedis.class.getName();
	public void run()
	{
		
	}
}
public class RedisAction extends Thread
{
	private static Logger vLogger = Logger.getLogger(RedisAction.class);
	private static String vName = RedisAction.class.getName();
	private CountDownLatch threadsSignal; 
	//dict的列数全局常量
	private final static String		DICTCOLSIZE			="@DICTCOLSIZE@";
	//redis的key的表名
	private final static String		CACHE_KEY_TABLE_NAME	=	"CACHE_KEY_TABLE_NAME";
	//key的分隔符
	private final static String		CACHE_KEY_SPLIT	=	"CACHE_KEY_SPLIT";
	//默认分隔符
	private final static String		DEF_CACHE_KEY_SPLIT	=	":";
	//主键列标识：可以为1个或者多个，以hash传入，key为PK_NAME1，PK_NAM2...PK_NAMEn
	private final static String		CACHE_KEY_PK_NAME	=	"PK_NAME";
	private final static String		CACHE_INDEX_PREFIX	=	"CACHE_IDX_";
	private final static String		RESULT	=	"RECORDSET";
	//private Base base;
	private Jedis JEDIS =null;
	private BusiObj	vDict	=	null;
	private boolean vWarnFlag		=	true;
	private	HashMap<String,String> vDbConfig	=	null;
	private	HashMap<String,String> vConfig=null;
	//private int thread_no	=0;
	public RedisAction(CountDownLatch threadsSignal) throws BaseException {
		//base = new Base(_conn);
		this.threadsSignal = threadsSignal; 
	}
	private void setJedis(Jedis jedis)throws BaseException
	{
		if(jedis==null)
			throw new BaseException("RDS-00007","redis connection为空，不能进行业务处理。");
		JEDIS=jedis;
	}
	public  void init(BusiObj	dDict )
	{
		vDict =dDict;
	}
	public void run() 
	{
		try {
			this.putDict2Redis(vDict);
		} catch (BaseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//throw new Exception();
		}
		threadsSignal.countDown();
		System.out.println(Thread.currentThread().getName() + "结束. 还有" + threadsSignal.getCount() + " 个线程");  
	}
	public void setConfig(HashMap<String,String> config)throws BaseException
	{
		vConfig	=	config;
	}
	public void setDbConfig(HashMap<String,String> dbConfig)throws BaseException
	{
		vDbConfig	=	dbConfig;
	}
	public void setWarnFlag(boolean warnFlag)throws BaseException
	{
		vWarnFlag	=	warnFlag;
	}
	public Jedis  getJedis(HashMap<String,String> dbConfig)throws BaseException
	{
		String ip 		=	dbConfig.get("IP");
		String port 	= dbConfig.get("PORT" );
		Jedis jedis = new Jedis(ip);
		return jedis;
	}
	private void checkJedis()throws BaseException
	{
		if(this.JEDIS==null)
				throw new BaseException("RDS-00008","redis connection为空，不能进行业务处理。");
	}
	private int  setDic2Redis(BusiObj	dDict,HashMap<String,String> config,boolean warnFlag)throws BaseException 
	{
		this.checkJedis();
		//load to redis
		int cnt	=		this.put2Redis(dDict, config,warnFlag);
		return cnt;//return records count
	}
	private void checkGlobalVar()throws BaseException
	{
		if(vDbConfig==null)
			throw new BaseException("RDS-00010","redis 连接配置信息为空，无法进行业务处理。");
		if(vConfig==null)
			throw new BaseException("RDS-00011","本次操作的表名及主键配置信息为空，无法进行业务处理。");
		if(vDict==null)
			throw new BaseException("RDS-00012","本次操作的数据信息为空，无法进行业务处理。");
		
	}
	public void putDict2Redis(BusiObj	dDict)throws BaseException 
	{
		this.checkGlobalVar();
		vLogger.info("=========多线程更新redis缓存=======线程号："+Thread.currentThread().getName() );
		long start_time=System.currentTimeMillis();
		this.putDict2Redis(vDbConfig, vDict, vConfig, vWarnFlag);
		long end_time=System.currentTimeMillis();
		vLogger.info("=========多线程更新redis缓存======="+"线程号："+Thread.currentThread().getName() +"，耗时（单位：毫秒）："+(end_time-start_time));
	}
	public void putDict2Redis(Jedis jedis,BusiObj	dDict,HashMap<String,String> config,boolean warnFlag)throws BaseException 
	{
		this.setJedis(jedis);
		this.setDic2Redis(dDict, config, warnFlag);
	}
	public void putDict2Redis(HashMap<String,String> dbConfig,BusiObj	dDict,HashMap<String,String> config,boolean warnFlag)throws BaseException 
	{
		Jedis jedis	=	this.getJedis(dbConfig);
		this.setJedis(jedis);
		this.setDic2Redis(dDict, config, warnFlag);
	}
	///////////////////////////////////////新版dict结构简化解析
	private ArrayList<HashMap> getDictResultSet(BusiObj	dDict)throws BaseException
	{
		HashMap<String, Object> mapOriginal	=		dDict.getRawData();
		//dict的原始结构是一个结果集节点下面是一个arrayList，list里面是hash
		ArrayList alResultSet	=		(ArrayList<HashMap>)mapOriginal.get(RESULT);
		return alResultSet;
	}
	private int getDictColSize(ArrayList<HashMap>alResultSet )throws BaseException 
	{
		return alResultSet.size();
	}
	///////////////////////////////////////新版dict结构简化解析
	//TODO 新版dict结构简化
	private int put2Redis(BusiObj	dDict,HashMap<String,String> config,boolean warnFlag)throws BaseException 
	{

		ArrayList<String>	alCacheKeyOfPK		=	new ArrayList<String>();
		ArrayList	<HashMap> alResultSet	=	this.getDictResultSet(dDict);
		int	cnt	=	this.getDictColSize(alResultSet);
		if(cnt==0)
			if (warnFlag)
				throw new BaseException("RDS-00001","dict记录数=0，没有可以处理的数据。");
			else
				return cnt;
		HashMap<String, Object> mapOriginal	=		dDict.getRawData();
		//dict的原始结构是一个结果集节点下面是一个arrayList，list里面是hash
		alCacheKeyOfPK		=	this.getCacheKeyOfPK(config);

		int i=0;
		long start_time=System.currentTimeMillis();
		try
		{
			for(HashMap oneRow:alResultSet)
			{
				long cycle_start_time=System.currentTimeMillis();
				i++;
				this.genOneRecord(alCacheKeyOfPK, oneRow,config);
				long cycle_end_time=System.currentTimeMillis();
				//System.out.println("本次总共："+cnt+"笔，已完成："+i+"笔。本笔耗时："+(cycle_end_time-cycle_start_time));
			}
			long end_time=System.currentTimeMillis();
			System.out.println("本次操作总共完成"+cnt+"笔；耗时（单位：毫秒）："+(end_time-start_time));
		}
		catch (Throwable e) {
			// TODO Auto-generated catch block
			long end_time=System.currentTimeMillis();
			System.out.println("本次总共："+cnt+"笔，已完成："+i+"笔；耗时（单位：毫秒）："+(end_time-start_time));
			e.printStackTrace();
			if(warnFlag)
				throw new BaseException("",e.getMessage());
			
		}

		return cnt;
	}
	
	//pk是有规则的，即一个hash，key=PK_NAME+i（主键中该列的顺序），value=pk的列名加上，
	//如ETL_JOB的pk是一个，则该hash为：key=PK_NAME1，value=JOB_ID
	//其缓存key=ETL_JOB:JOB_ID,value=hash，即整条记录
	//如ETL_TEST的pk是三个，则该hash为：
											//key=PK_NAME1，value=JOB_ID
											//key=PK_NAME2，value=STAGE_ID
	//其缓存key=ETL_TEST:JOB_ID:STAGE_ID,value=hash，即整条记录
	private ArrayList<String> getCacheKeyOfPK(HashMap<String,String> config)throws BaseException 
	{
		String	cacheKeyOfPK	=	"";
		ArrayList<String> alCacheKeyOfPK	=	new ArrayList<String>();
		for(int i=1;i<99;i++)
		{
			cacheKeyOfPK=	config.get(CACHE_KEY_PK_NAME+i);
			if(this.isStrNullOrEmpty(cacheKeyOfPK))
			{
				if(i==0)
					throw new BaseException("RDS-00004","缓存key没有指定主键（至少一个），无法生成缓存。");
				else
					break;
			}
			alCacheKeyOfPK.add(cacheKeyOfPK);
		}
		return alCacheKeyOfPK;
	}
	//TODO
	//生成记录，包括主键值，记录
	//确保入参为hash
	//生成记录，还需考虑索引方式，list or hash？不需要了，keys命令即可
	private void genOneRecord(ArrayList<String>alCacheKeyOfPK,HashMap<String,String>hRecord,HashMap<String,String>config)throws BaseException 
	{
		String pkValue	=	"",pkColValue="",pkName="";
		String	table				=	this.getCacheKeyOfTable(config);
		String	split				=	this.getCacheKeyOfSplit(config);

		for(String pkColName:alCacheKeyOfPK)
		{
			
			pkColValue	=	hRecord.get(pkColName);//+CACHE_KEY_SPLIT
			if(this.isStrNullOrEmpty(pkColValue))
				throw new BaseException("RDS-00005","缓存key指定主键列（"+pkColName+"）的值为空，无法生成缓存。");
			pkValue	=	pkValue+split+pkColValue;
			pkName	=	pkName+split+pkColName;
		}
		String	cacheKey		=	table+pkName+pkValue; //+split，由于前面组成pkValue的时候已处理
		double dRandom=Math.random();
		int iRandom	=	(int) (dRandom*1000);
		if(iRandom==500)
			vLogger.info("dRandom="+dRandom+"==============cacheKey:"+cacheKey);
		//System.out.println("==============cacheKey:"+cacheKey);
		this.JEDIS.hmset(cacheKey, hRecord);
	}
	public boolean isStrNullOrEmpty(String str)
	{
		boolean flag =false;
		if(str ==null || str.trim().equals(""))
			flag=true;
		return flag;
	}
	private String getCacheKeyOfTable(HashMap<String,String> config)throws BaseException 
	{
		String	cacheKeyOfTable	=	config.get(CACHE_KEY_TABLE_NAME);
		if(this.isStrNullOrEmpty(cacheKeyOfTable))
			throw new BaseException("RDS-00003","缓存key没有指定表名，无法生成缓存。");
		return cacheKeyOfTable;
	}
	private String getCacheKeyOfSplit(HashMap<String,String> config)throws BaseException 
	{
		String	cacheKeyOfSplite	=	config.get(CACHE_KEY_SPLIT);
		if(this.isStrNullOrEmpty(cacheKeyOfSplite))
			cacheKeyOfSplite	=	DEF_CACHE_KEY_SPLIT;
		return cacheKeyOfSplite;
	}
	private boolean checkDictColumnSize(HashMap<String, Integer> hListSize) throws BaseException 
	{
		boolean flag	=	false;
		int	iBeforeSize	=	0,iCurrentSize =0,		cnt	=	0;
		for   (String key  : hListSize.keySet())
		{
			cnt++;
			iCurrentSize	=	hListSize.get(key);
			if(iBeforeSize !=iCurrentSize)
			{
				if(cnt==1)
					continue;
				else
					return flag;
			}
			iBeforeSize =iCurrentSize;
				
		}
		flag	=	true;
		return flag;
	}
	/////////////////////////////////ibss的老版本dict解析，废弃/////////////////////////////////
	//TODO ibss的老版本dict解析，废弃
	@Deprecated
	private HashMap<String, Integer> getDictCols(HashMap<String, Object> map) throws BaseException 
	{
		ArrayList alObj			=	new ArrayList();
		HashMap<String, Integer> hListSize	=	new HashMap<String, Integer> ();
		int			cnt			=	0;
		for   (String key  : map.keySet())//获得列，要转换成hash
		  {
			  Integer listSize=0;
			  Object value		=	map.get(key);
			  if(value==null)
			  {
				  listSize=0;
			  }
			  else if (value.getClass().getName().equals("java.util.ArrayList")) 
			  {
				  alObj = (ArrayList) value;
				  listSize	=	Integer.valueOf( alObj.size());	
			  }
			  else if (value.getClass().getName().equals("java.lang.String")) 
			  {
				  listSize=1;
			  }
			  hListSize.put(key, listSize);
			  cnt	=	listSize;
		  }
		return hListSize;
	}
	@Deprecated
	private HashMap<String, Integer> getDictColSize(BusiObj	dDict)throws BaseException 
	{
		HashMap<String, Object> map	=		dDict.getRawData();
		ArrayList alObj			=	new ArrayList();
		HashMap<String, Integer> hListSize	=	new HashMap<String, Integer> ();
		Integer listSize=0;
		for   (String key  : map.keySet())//获得列，要转换成hash
		  {

			  Object value		=	map.get(key);
			  if(value==null)
			  {
				  listSize=0;
			  }
			  else if (value.getClass().getName().equals("java.util.ArrayList")) 
			  {
				  alObj = (ArrayList) value;
				  listSize	=	Integer.valueOf( alObj.size());	
			  }
			  else if (value.getClass().getName().equals("java.lang.String")) 
			  {
				  listSize=1;
			  }
			  hListSize.put(key, listSize);
		  }
		hListSize.put(DICTCOLSIZE, listSize);
		return hListSize;
	}
	@Deprecated
	private void transfer2Hash(BusiObj	dDict,HashMap<String,String> config,int cnt)throws BaseException 
	{
		if(cnt<=0)
			throw new BaseException("RDS-00006","dict记录数=0，没有可以处理的数据。");
		ArrayList<String>	alCacheKeyOfPK		=	new ArrayList<String>();
		
		HashMap<String, Object> mapOriginal	=		dDict.getRawData();
		//dict的原始结构是一个结果集节点下面是一个arrayList，list里面是hash
		HashMap<String, Object> map	=		(HashMap<String, Object>)mapOriginal.get(RESULT);
		alCacheKeyOfPK		=	this.getCacheKeyOfPK(config);

		for(int i=0;i<cnt;i++)
		{
			String pk ="";
			//单记录，由于可能是hashMap<String,String>，因此需要分开处理
			if(cnt==1)
			{
				HashMap<String,String>	hRecord=	new HashMap<String,String>();
				for(String key:map.keySet())
				{
					hRecord.put(key,  (String)map.get(key));
				}
				this.genOneRecord(alCacheKeyOfPK, hRecord,config);
			}
				
			else
			{
				//多条记录的循环生成。
				for(int iRecNumber=0;iRecNumber<cnt;iRecNumber++)
				{
					HashMap<String,String>	hRecord=	new HashMap<String,String>();
					for(String key:map.keySet())
					{
						ArrayList<String> alColData	=	new ArrayList<String> ();
						alColData= (ArrayList<String> )map.get(key);
						hRecord.put(key, alColData.get(iRecNumber));
					}
					this.genOneRecord(alCacheKeyOfPK, hRecord,config);
				}
			}
		}

	}
/*	public void setThreadNo(int threadNo)
	{
		thread_no	=	threadNo;
	}*/
	private static ArrayList<ArrayList <HashMap>>initMultiThreadList(int thread_cnt )throws BaseException
	{
		ArrayList<ArrayList <HashMap>>	alResult=	new ArrayList<ArrayList <HashMap>>();
		for(int i=0;i<thread_cnt;i++)
		{
			ArrayList <HashMap> alTemp	=	new ArrayList <HashMap>();
			alResult.add(alTemp);
		}
		return alResult;
	}
	private static ArrayList<BusiObj> genMultiThreadDict(ArrayList<ArrayList <HashMap>>alResult)throws BaseException
	{
		ArrayList<BusiObj> alDict	=	new ArrayList<BusiObj>();
		for(ArrayList <HashMap> oneResult:alResult)
		{
			BusiObj aDict	=	new BusiObj();
			HashMap<String, Object> mapOriginal	=	new HashMap<String, Object>();
			mapOriginal.put(RESULT, oneResult);
			//aDict.getRawData()	=mapOriginal	;
			alDict.add(aDict);			
		}
		return alDict;
	}
	public static ArrayList<BusiObj> splitDictForMultiThread(BusiObj dDict,int thread_cnt )throws BaseException
	{
		HashMap<String, Object> mapOriginal	=		dDict.getRawData();
		//dict的原始结构是一个结果集节点下面是一个arrayList，list里面是hash
		ArrayList <HashMap>alResultSet	=		(ArrayList<HashMap>)mapOriginal.get(RESULT);
		ArrayList<BusiObj>	alDict	=	new ArrayList<BusiObj>();
		ArrayList<ArrayList <HashMap>>	alResult=	RedisAction.initMultiThreadList(thread_cnt);
		int i=1;
		for(HashMap oneRow:alResultSet)
		{
			//取模分装到多个dict
			int mod	=	i%thread_cnt;
			alResult.get(mod).add(oneRow);
			i++;
		}
		alDict	=	RedisAction.genMultiThreadDict(alResult);
		return alDict;
	}
	//TODO  ibss的老版本dict解析，废弃
	//TODO
	/////////////////////////////////ibss的老版本dict解析，废弃/////////////////////////////////
	public static void main(String[] args) throws BaseException  
	{
		SQLArgs			vArg				= new SQLArgs();
		String 	ip				=	args[0];
		String	port	=	args[1];
		String	flagMultiThread	=	args[2];//0,单线程，其余多线程
		int threadNum=20,assignThreadNum=0;
		int  MAXTHREADNUM=30;
		try
		{
			assignThreadNum	=	Integer.valueOf(flagMultiThread);
			if(assignThreadNum>0&&assignThreadNum<=MAXTHREADNUM)
				;
			else if(assignThreadNum>MAXTHREADNUM)
				assignThreadNum=MAXTHREADNUM;
			else if(assignThreadNum<=0)
				assignThreadNum	=1;
			threadNum=assignThreadNum;
		}
		catch(Exception e)
		{
			vLogger.info("=========入参错误:第三个参数必须为数字型，将使用单线程模式");
		}
		//PropertyConfigurator.configure("log4j.properties");
		HashMap<String,String> dbConfig	= new HashMap<String,String>();

		try {
			long start_time=System.currentTimeMillis();
			Logger vLogger = Logger.getLogger(RedisAction.class);
			dbConfig.put("IP", ip);
			dbConfig.put("PORT", port);
			Jedis jedis = new Jedis(ip);
			Connection conn = DBTrans.getConnection();
			//Base base	=	new Base(conn);
			vArg.reset();
			String get_redis_sql 					=	" select table_name,max_row,pk_names  from redis_config where state=1 ";
			BusiObj rRet;
			rRet=OperAgent.execQuery(conn, "Query order_info " ,get_redis_sql, vArg);
			//rRet = base.query("-22122171", "RECORDSET", get_redis_sql, new String[] { });
			HashMap<String, Object> mapRedisConfig	=		rRet.getRawData();
			HashMap hRedisConfig	=		((ArrayList<HashMap>)mapRedisConfig.get(RESULT)).get(0);
			
			String table_name = (String) hRedisConfig.get("TABLE_NAME");
			String max_row = (String) hRedisConfig.get("MAX_ROW");
			String pk_names = (String) hRedisConfig.get("PK_NAMES");
			String[] lPkName	=	pk_names.split(":");
			
			HashMap<String,String> config	= new HashMap<String,String> ();
			int iPks=0;
			for(String value:lPkName)
			{
				iPks++;
				config.put(CACHE_KEY_PK_NAME+iPks, value);
				
			}
			CountDownLatch threadSignal = new CountDownLatch(threadNum);//初始化countDown
			int iMaxRow	=	Integer.valueOf(max_row);
			boolean bSplitQuery	=	false;
			if(iMaxRow>50000)
				bSplitQuery	=	true;
			RedisAction redisAction	=	new RedisAction(threadSignal);
			vLogger.info("=========1、查询数据库=======");
			String 	condition = " and rownum< "+max_row;
			BusiObj dRet;
			String cntSql 					=	" select count(1) from "+table_name+" where 1=1 "+condition;
			int iCnt	=	OperAgent.QueryInt(conn, "", cntSql, vArg);
			int iCycle=0;
			int BATCH=50000;
			if(iCnt>BATCH)
				iCycle=iCnt/BATCH+1;
			vLogger.info("\n\n=========记录总共："+iCnt+"\n循环次数："+iCycle);
			long	db_all_time=0L;
			for(int j=0;j<iCycle;j++)
			{
				long this_start_time=System.currentTimeMillis();
				long db_start_time=System.currentTimeMillis();
				condition=" and rownum>"+j*BATCH+" and rownum< "+(j+1)*BATCH;
				String sql 					=	" select * from "+table_name+" where 1=1 "+condition;
				dRet = OperAgent.execQuery(conn, "Query order_info " ,sql, vArg);

				String		CACHE_KEY_TABLE_NAME	=	"CACHE_KEY_TABLE_NAME";
				//key的分隔符
				 String		CACHE_KEY_SPLIT	=	"CACHE_KEY_SPLIT";
				 
				//主键列标识：可以为1个或者多个，以hash传入，key为PK_NAME1，PK_NAM2...PK_NAMEn

				config.put(CACHE_KEY_TABLE_NAME, table_name.toUpperCase());
				config.put(CACHE_KEY_SPLIT, "-");
	/*			config.put(CACHE_KEY_PK_NAME+"1", "SATTR_ID");
				config.put(CACHE_KEY_PK_NAME+"2", "DOBJECT_ID");*/
				boolean warnFlag = true;
				long db_end_time=System.currentTimeMillis();
				db_all_time+=(db_end_time-db_start_time);
				vLogger.info("=========2、更新redis缓存=======");
				if(flagMultiThread.trim().equals("1"))//单线程
				{
					vLogger.info("=========2-1、单线程更新redis缓存=======");
					redisAction.putDict2Redis(dbConfig, dRet, config, warnFlag);
					vLogger.info("=========2-1、单线程更新redis缓存=======");
				}
				else//多线程
				{
					vLogger.info("=========2-2、多线程更新redis缓存=======");
					HashMap<String, Object> mapOriginal	=		dRet.getRawData();
					//dict的原始结构是一个结果集节点下面是一个arrayList，list里面是hash
					ArrayList <HashMap>alResultSet	=		(ArrayList<HashMap>)mapOriginal.get(RESULT);
					
					 ArrayList<BusiObj>alDict	=	RedisAction.splitDictForMultiThread(dRet, threadNum);
					int i=1;
					for(BusiObj aDict:alDict)
					{
						RedisAction multiThreadRedisAction	=	new RedisAction(threadSignal);
						multiThreadRedisAction.setWarnFlag(warnFlag);
						multiThreadRedisAction.setConfig(config);
						multiThreadRedisAction.setDbConfig(dbConfig);
						multiThreadRedisAction.init(aDict);
	/*					multiThreadRedisAction.setThreadNo(i);*/
						Thread t = multiThreadRedisAction;
						t.start();
					}
					threadSignal.await();//等待所有子线程执行完  
					System.out.println(Thread.currentThread().getName() + "结束.");//打印结束标记 
					vLogger.info("=========2-2、多线程更新redis缓存=======");
					vLogger.info("\n====================init put redis over====================\n");
					long this_end_time=System.currentTimeMillis();
					vLogger.info("\n\n--------------- put redis 本次过程耗时："+(this_end_time- this_start_time)+"\n\n其中本次数据库查询耗时："+(db_end_time- start_time));

			}
				long global_end_time=System.currentTimeMillis();
				vLogger.info("\n\n--------------- put redis 总过程耗时："+(global_end_time- start_time)+"\n\n其中数据库查询耗时："+db_all_time);
/*			String sql 					=	" select * from "+table_name+" where 1=1 "+condition;
			dRet = base.query("-22122170", "RECORDSET", sql, new String[] { });

			String		CACHE_KEY_TABLE_NAME	=	"CACHE_KEY_TABLE_NAME";
			//key的分隔符
			 String		CACHE_KEY_SPLIT	=	"CACHE_KEY_SPLIT";
			 
			//主键列标识：可以为1个或者多个，以hash传入，key为PK_NAME1，PK_NAM2...PK_NAMEn

			config.put(CACHE_KEY_TABLE_NAME, table_name.toUpperCase());
			config.put(CACHE_KEY_SPLIT, "-");
			config.put(CACHE_KEY_PK_NAME+"1", "SATTR_ID");
			config.put(CACHE_KEY_PK_NAME+"2", "DOBJECT_ID");
			boolean warnFlag = true;
			long db_end_time=System.currentTimeMillis();
			vLogger.info("=========2、更新redis缓存=======");
			if(flagMultiThread.trim().equals("1"))//单线程
			{
				vLogger.info("=========2-1、单线程更新redis缓存=======");
				redisAction.putDict2Redis(dbConfig, dRet, config, warnFlag);
				vLogger.info("=========2-1、单线程更新redis缓存=======");
			}
			else//多线程
			{
				vLogger.info("=========2-2、多线程更新redis缓存=======");
				HashMap<String, Object> mapOriginal	=		dRet.valueMap;
				//dict的原始结构是一个结果集节点下面是一个arrayList，list里面是hash
				ArrayList <HashMap>alResultSet	=		(ArrayList<HashMap>)mapOriginal.get(RESULT);
				
				 ArrayList<BusiObj>alDict	=	RedisAction.splitDictForMultiThread(dRet, threadNum);
				int i=1;
				for(BusiObj aDict:alDict)
				{
					RedisAction multiThreadRedisAction	=	new RedisAction(threadSignal);
					multiThreadRedisAction.setWarnFlag(warnFlag);
					multiThreadRedisAction.setConfig(config);
					multiThreadRedisAction.setDbConfig(dbConfig);
					multiThreadRedisAction.init(aDict);
					multiThreadRedisAction.setThreadNo(i);
					Thread t = multiThreadRedisAction;
					t.start();
				}
				threadSignal.await();//等待所有子线程执行完  
				System.out.println(Thread.currentThread().getName() + "结束.");//打印结束标记 
				vLogger.info("=========2-2、多线程更新redis缓存=======");*/
				  //jedis.hmset(tableName+separator+order_num, hash);
/*				jedis.lpush(order_num, m);
				jedis.lpush(key, string)*/

			}

			jedis.disconnect();
/*			vLogger.info("\n====================init put redis over====================\n");
			long end_time=System.currentTimeMillis();
			vLogger.info("\n\n--------------- put redis 总过程耗时："+(end_time- start_time)+"\n\n其中数据库查询耗时："+(db_end_time- start_time));
*/
			conn.close();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
